package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.mylibrary.utils.DisplayUtil;

import java.util.ArrayList;
import java.util.List;

public class RadioActivity extends AppCompatActivity {
    List<String>list=new ArrayList<>();
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_radio);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        CheckBox checkBox =findViewById(R.id.checkBox);
        CheckBox checkBox2 =findViewById(R.id.checkBox2);
        CheckBox checkBox3 =findViewById(R.id.checkBox3);
        MyCheckedChanged changed = new MyCheckedChanged();
        checkBox.setOnCheckedChangeListener(changed);
        checkBox2.setOnCheckedChangeListener(changed);
        checkBox3.setOnCheckedChangeListener(changed);
        findViewById(R.id.imageButton).setOnClickListener((view)->{
            DisplayUtil.displayToast(RadioActivity.this,"您总共选择了"+list.size()+"项\n"+list);
        });
    }
    private class MyCheckedChanged implements CompoundButton.OnCheckedChangeListener{
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            String boxText=compoundButton.getText().toString();
            if (b) {
                // 当CheckBox被选中时执行的操作
                DisplayUtil.displayToast(RadioActivity.this, "您选择了"+boxText);
                list.add(boxText);
            }else {
                list.remove(boxText);
            }
        }
    }
}
